package com.dingding.controller;

import com.dingding.entity.request.user.UserUpdateRequest;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSort;
import com.dingding.entity.request.user.UserListRequest;
import com.dingding.entity.BasePageResponse;
import com.dingding.entity.BaseResponse;
import com.dingding.entity.response.user.UserInfoResponse;
import com.dingding.entity.request.DeleteRequest;
import com.dingding.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(value = "用户管理", tags = {"2. 用户管理"})
public class UserManageController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 用户管理用户列表
     *
     * @author DingXintao
     * @date 2023/9/11 13:44
     * @param req
     * @return com.marketingtool.controller.response.BasePageResponse<java.util.List<com.marketingtool.controller.response.user.UserInfoResponse>>
     **/
    @ApiOperationSort(1)
    @ApiOperation(value = "1. 用户列表", notes = "用户列表分页查询")
    @PostMapping("manage/list")
    public BasePageResponse<List<UserInfoResponse>> manageUserList(@RequestBody UserListRequest req) {
        log.info("=======enter /user/manage/list");
        return userService.manageUserList(req);
    }

    /**
     * 用户邮箱认证记录删除
     *
     * @author DingXintao
     * @date 2023/9/12 17:19
     * @param req
     * @return com.marketingtool.controller.response.BaseResponse
     **/
    @ApiOperationSort(3)
    @ApiOperation(value = "3. 用户删除", notes = "用户删除")
    @PostMapping("/manage/delete")
    public BaseResponse manageUserListDelete(@RequestBody @Validated DeleteRequest req) {
        log.info("=======enter /user/manage/manageUserListDelete={}", req);
        return userService.manageUserListDelete(req.getDeleteIds());
    }

    /**
     * 用户修改+新增
     *
     * @author DingXintao
     * @date 2023/9/11 13:44
     * @param req
     * @return com.marketingtool.controller.response.BaseResponse
     **/
    @ApiOperationSort(2)
    @ApiOperation(value = "2. 用户修改", notes = "用户修改")
    @PostMapping("manage/update")
    public BaseResponse<UserInfoResponse> manageUserUpdate(@Validated UserUpdateRequest req) throws Exception{
        log.info("=======enter /user/manage/update={}", req);
        return userService.manageUserUpdate(req);
    }

}
